package IOperation;

import BOOK.Book;
import BOOK.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: wenxiwen
 * Date: 2022/4/14
 * Time: 20:31
 * Description: No Description
 */
public class Del implements IOperation{
    public void work(BookList bookList) {
        System.out.println("删除图书");

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入要删除的书籍名称：");
        String name = scan.nextLine();
        int count = 0;
        int index = bookList.getCount();
        int i = 0;
        for (i = 0; i < index; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                count = i;
                break;
            }
        }

        for (int j = count; j < index - 1; j++) {
            bookList.setBook(j,bookList.getBook(j+1));
        }
        bookList.setBook(index ,null);
        bookList.setCount(index-1);
        System.out.println("删除成功！");
    }
}